<template>
	<rh-wx class="store-write-fail-container">
		<template>			
			<view class="app-status-content flex-column">
				<image class="app-icon" src="@/static/image/logo.png" mode="aspectFill"></image>
				<view class="status-content flex-center">
					<text class="status-txt">您正在绑定为该店铺的核销员</text>
				</view>
			</view>
			<rh-submit-btn class="submit-btn" text="立即绑定" :submit-action="submit"></rh-submit-btn>
		</template>
	</rh-wx>
</template>

<script>
	import {getWxCode, getUrlCode, isWechat} from '@/script/wx-premission.js'
	import {bindShop} from '@/api/store/index.js'
	export default {
		data() {
			return {
				isWechat: isWechat(),
				userInfo: {},
				routeParams: {}
			}
		},
		onLoad(e) {
			if(!this.isWechat) return
			let code = getUrlCode('code')
			if(!code) {
				getWxCode(location.href)
			}
		},
		methods: {
			submit(){
				let _self = this
				if(!_self.isWechat) return _self.$attention.noIcon('请在微信浏览器中使用')
				return new Promise((resolve, reject) => {
					if(!getUrlCode('code')){
						_self.$attention.noIcon(`授权失败，请重新扫码！`)
						resolve(false)
					}else{
						let params = {
							code: getUrlCode('code'),
							writeOffUserId: getUrlCode('id')
						}
						bindShop(params).then(res => {
							setTimeout(() => {
								_self.$$router.replace({
									name: 'walletSuccess', 
									query: {type: 'bindShop'},
								})
							}, 500)
						}).finally(() => {
							resolve(true)
						})
					}
				})
			},
		}

	}
</script>
<style lang="scss" scoped>
	@mixin fontStyle($color, $size, $weight: 500) {
		color: $color;
		font-size: $size;
		font-weight: $weight;
	}
	.store-write-fail-container{
		min-height: 100vh;
		background-color: #F4F8F9;
		padding: 0 20rpx 180rpx;
		.app-status-content{
			align-items: center;
			padding-top: 100rpx;
			.app-icon{
				width: 196rpx;
				height: 196rpx;
				border-radius: 6rpx;
			}
			.status-content{
				margin-top: 60rpx;
				.status-txt{
					margin-left: 20rpx;
					@include fontStyle(#444444, 28rpx);
				}
			}
		}
		.desc-content{
			margin-top: 140rpx;
			padding: 0 20rpx 40rpx;
			.desc-label{
				@include fontStyle(#3D3D3D, 32rpx);
			}
			.desc-list{
				margin-top: 32rpx;
				.item{
					margin-bottom: 10rpx;
					text-align: justify;
					@include fontStyle(#3D3D3D, 28rpx);
					&:last-child{
						margin-bottom: 0;
					}
				}
			}
		}
	}
</style>


